package dailytest;

import java.util.Calendar;
import java.util.Date;

/**
 * @author: heweiwei
 * @Date: 2023/1/10 11:43
 * @Desc:
 */
public class Utils {

    public static int getDayCount(Date date1, Date date2) {
        Calendar cal1 = getDateZeroCalendar(date1);
        Calendar cal2 = getDateZeroCalendar(date2);
        long times = Math.abs(cal1.getTime().getTime() - cal2.getTime().getTime());
        times += 43200000L;
        long between_days = times / 86400000L;
        return Integer.parseInt(String.valueOf(between_days));
    }

    public static Calendar getDateZeroCalendar(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        setTimeToBeginningOfDay(cal);
        return cal;
    }

    private static void setTimeToBeginningOfDay(Calendar calendar) {
        calendar.set(11, 0);
        calendar.set(12, 0);
        calendar.set(13, 0);
        calendar.set(14, 0);
    }
}
